#include "stdafx.h"
#include <stdarg.h>
#include <math.h>
#include "GWFuncs.h"

//------------------------------------------------------------------------------
// Global Variables
// Scan functions variables. These are pointers to various parts of guild wars code
byte* BasePointerLocation = NULL;
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// Guild Wars function stuff
void Scan()
{
	byte* startaddr = (byte*)0x00401000;
    byte* endaddr = (byte*)0x00900000;

    // Scan Codes:
    byte BasePointerLocationCode[] = {0x8B, 0x46, 0x38, 0x85, 0xC0, 0x8D, 0x50, 0xFF};
    // :Scan Codes

    while (startaddr < endaddr) {
        if(!memcmp(startaddr, BasePointerLocationCode, sizeof(BasePointerLocationCode))) {
			BasePointerLocation = (byte*)(*(dword*)(startaddr-8));
		}

        // Check if we can exit scan loop early
        if (BasePointerLocation) { return; }
		startaddr++;
	}
}

long GetTimeInTheMap() // Gets time the current instance has been alive in ms
{
        try {
                DWORD buffer;
                memcpy(&buffer,BasePointerLocation,4);
                buffer+= 0x18;
                memcpy(&buffer,(void*) buffer,4);
                buffer+= 0x08;
                memcpy(&buffer,(void*) buffer,4);
                buffer+= 0x1AC;
                memcpy(&buffer,(void*) buffer,4);
                return buffer;
        }
        catch(...) {
                return 0;
        }
}
//------------------------------------------------------------------------------
